home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / amitcp / httpd.lha / httpd / httpd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-18  |  12.5 KB  |  528 lines

  1. /*
  2.  * httpd.h: header for simple (ha! not anymore) http daemon
  3.  */
  4.  
  5. #ifndef AMIGA
  6. #define VOID_PARMS /*none*/
  7. #else
  8. #define VOID_PARMS void
  9. #endif
  10.  
  11. /* Define one of these according to your system. */
  12. #if defined(SUNOS4)
  13. #define BSD
  14. #undef NO_KILLPG
  15. #undef NO_SETSID
  16. char *crypt(char *pw, char *salt);
  17.  
  18. #elif defined(SOLARIS2)
  19. #undef BSD
  20. #define NO_KILLPG
  21. #undef NO_SETSID
  22. #define bzero(a,b) memset(a,0,b)
  23.  
  24. #elif defined(IRIX)
  25. #undef BSD
  26. #undef NO_KILLPG
  27. #undef NO_SETSID
  28.  
  29. #elif defined(HPUX)
  30. #undef BSD
  31. #define NO_KILLPG
  32. #undef NO_SETSID
  33.  
  34. #elif defined(AIX)
  35. #undef BSD
  36. #undef NO_KILLPG
  37. #undef NO_SETSID
  38.  
  39. #elif defined(ULTRIX)
  40. #define BSD
  41. #undef NO_KILLPG
  42. #undef NO_SETSID
  43. #define ULTRIX_BRAIN_DEATH
  44. #define NEED_STRDUP
  45.  
  46. #elif defined(OSF1)
  47. #define BSD
  48. #undef NO_KILLPG
  49. #undef NO_SETSID
  50.  
  51. #elif defined(SEQUENT)
  52. #define BSD
  53. #undef NO_KILLPG
  54. #define NO_SETSID
  55. #define NEED_STRDUP
  56. #define tolower(c) (isupper(c) ? tolower(c) : c)
  57.  
  58. #elif defined(NEXT)
  59. #define BSD
  60. #undef NO_KILLPG
  61. #define NO_SETSID
  62. #define NEED_STRDUP
  63. #define _POSIX_SOURCE
  64. #define S_ISDIR(m)      (((m)&(S_IFMT)) == (S_IFDIR))
  65. #define S_ISREG(m)      (((m)&(S_IFMT)) == (S_IFREG))
  66. #define S_IXUSR 00100
  67. #define S_IXGRP 00010
  68. #define S_IXOTH 00001
  69. #define STDIN_FILENO  0
  70. #define STDOUT_FILENO 1
  71. #define STDERR_FILENO 2
  72. #define waitpid(a,b,c) wait4(a,b,c,NULL)
  73. #define NEED_PUTENV
  74. typedef int pid_t;
  75.  
  76. #elif defined(LINUX)
  77. #undef BSD
  78. #undef NO_KILLPG
  79. #undef NO_SETSID
  80. #undef NEED_STRDUP
  81.  
  82. #elif defined(SCO)
  83. #undef BSD
  84. #undef NO_KILLPG
  85. #undef NO_SETSID
  86. #define NEED_INITGROUPS
  87.  
  88. #elif defined(CONVEXOS)
  89. #define BSD
  90. #define NEED_STRDUP
  91.  
  92. #elif defined(AUX)
  93. #undef BSD
  94. #undef NO_KILLPG
  95. #undef NO_SETSID
  96. #define NEED_STRDUP
  97. #define _POSIX_SOURCE
  98.  
  99. #elif defined(AMIGA)
  100. #define BSD
  101. #define NO_KILLPG
  102. #define NO_SETSID
  103. #define NO_NCSA_EXEC
  104. #define NO_INCLUDE_COMMANDS
  105. /*#define NO_SECURITY*/
  106. #undef NEED_STRDUP
  107. /*#define NEED_INITGROUPS*/
  108. #define COLON_SEPARATOR
  109. #define _POSIX_SOURCE
  110. #define strcasecmp stricmp
  111. #define strncasecmp strnicmp
  112. #define SIGKILL SIGTERM
  113. #define S_ISDIR(m)      (((m)&(S_IFMT)) == (S_IFDIR))
  114. #define S_ISREG(m)      (((m)&(S_IFMT)) == (S_IFREG))
  115. #define S_IXUSR 00100
  116. #define S_IXGRP 00010
  117. #define S_IXOTH 00001
  118. #define STDIN_FILENO  0
  119. #define STDOUT_FILENO 1
  120. #define STDERR_FILENO 2
  121. #define fprintf __SaFprintf
  122. #define fclose __SaFclose
  123. #define fwrite __SaFwrite
  124. #define fputs __SaFputs
  125. #define fputc __SaFputc
  126. #define fflush __SaFflush
  127.  
  128. /* Unknown system - Edit these to match */
  129. #else
  130. /* BSD is whether your system uses BSD calls or System V calls. */
  131. #define BSD
  132. /* NO_KILLPG is set on systems that don't have killpg */
  133. #undef NO_KILLPG
  134. /* NO_SETSID is set on systems that don't have setsid */
  135. #undef NO_SETSID
  136. /* NEED_STRDUP is set on stupid systems that don't have strdup. */
  137. #undef NEED_STRDUP
  138. #endif
  139.  
  140. /*
  141.  * The particular directory style your system supports. If you have dirent.h
  142.  * in /usr/include (POSIX) or /usr/include/sys (SYSV), #include 
  143.  * that file and define DIR_TYPE to be dirent. Otherwise, if you have 
  144.  * /usr/include/sys/dir.h, define DIR_TYPE to be direct and include that
  145.  * file. If you have neither, I'm confused.
  146.  */
  147. #if !defined(NEXT) && !defined(CONVEXOS)
  148. #include <dirent.h>
  149. #define DIR_TYPE dirent
  150. #else
  151. #include <sys/dir.h>
  152. #define DIR_TYPE direct
  153. #endif
  154.  
  155. /* ----------------------------- config dir ------------------------------ */
  156.  
  157. /* Define this to be the default server home dir. Anything later in this
  158.  * file with a relative pathname will have this added.
  159.  */
  160. #define HTTPD_ROOT "/usr/local/etc/httpd"
  161. #ifdef AMIGA
  162. #undef HTTPD_ROOT
  163. #define HTTPD_ROOT "http:"
  164. #endif
  165. /* Root of server */
  166. #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
  167. #ifdef AMIGA
  168. #undef DOCUMENT_LOCATION
  169. #define DOCUMENT_LOCATION "http:htdocs"
  170. #endif
  171.  
  172. /* Max. number of aliases */
  173. #define MAX_ALIASES 20
  174.  
  175. /* Max. number of security defines */
  176. #define MAX_SECURITY 50
  177.  
  178. /* Max. number of include files */
  179. #define MAXINCLUDES 20
  180.  
  181. #ifdef AMIGA
  182. /* Max. number of groups (whatever these are ) */
  183. #define NGROUPS_MAX (20)
  184. #endif
  185.  
  186. /* Default administrator's address */
  187. #define DEFAULT_ADMIN "[no address given]"
  188.  
  189. /* 
  190.  * --------- You shouldn't have to edit anything below this line ----------
  191.  *
  192.  * Any modifications to any defaults not defined above should be done in the 
  193.  * respective config. file. 
  194.  *
  195.  */
  196.  
  197.  
  198. /* -------------- Port number for server running standalone --------------- */
  199.  
  200. #define DEFAULT_PORT 80
  201.  
  202. /* --------- Default user name and group name running standalone ---------- */
  203. /* --- These may be specified as numbers by placing a # before a number --- */
  204.  
  205. #define DEFAULT_USER "#-1"
  206. #define DEFAULT_GROUP "#-1"
  207.  
  208. /* The name of the log files */
  209. #define DEFAULT_XFERLOG "logs/access_log"
  210. #define DEFAULT_ERRORLOG "logs/error_log"
  211. #define DEFAULT_PIDLOG "logs/httpd.pid"
  212.  
  213. /* Define this to be what your HTML directory content files are called */
  214. #define DEFAULT_INDEX "index.html"
  215.  
  216. /* Define this to be what type you'd like returned for files with unknown */
  217. /* suffixes */
  218. #define DEFAULT_TYPE "text/html"
  219.  
  220. /* Define this to be what your per-directory security files are called */
  221. #define DEFAULT_ACCESS_FNAME ".htaccess"
  222.  
  223. /* The name of the server config file */
  224. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  225.  
  226. /* The name of the document config file */
  227. #define RESOURCE_CONFIG_FILE "conf/srm.conf"
  228.  
  229. /* The name of the MIME types file */
  230. #define TYPES_CONFIG_FILE "conf/mime.types"
  231.  
  232. /* The name of the access file */
  233. #define ACCESS_CONFIG_FILE "conf/access.conf"
  234.  
  235.  
  236. /* The default directory in user's home dir */
  237. #define DEFAULT_USER_DIR "public_html"
  238.  
  239.  
  240. /* The default string lengths */
  241. #define MAX_STRING_LEN 256
  242. #define HUGE_STRING_LEN 8192
  243.  
  244. /* The timeout for waiting for messages */
  245. #define DEFAULT_TIMEOUT 1200
  246.  
  247.  
  248. /* ------------------------------ error types ------------------------------ */
  249.  
  250. #define SERVER_VERSION "NCSA/1.0"
  251. #define SERVER_PROTOCOL "HTTP/1.0"
  252. #define SERVER_SUPPORT "httpd@ncsa.uiuc.edu"
  253.  
  254. #define REDIRECT 302
  255. #define BAD_REQUEST 400
  256. #define AUTH_REQUIRED 401
  257. #define FORBIDDEN 403
  258. #define NOT_FOUND 404
  259. #define SERVER_ERROR 500
  260. #define NOT_IMPLEMENTED 501
  261. #define INCLUDE_ERROR 6991
  262.  
  263. #define METHODS 3
  264. #define M_GET 0
  265. #define M_PUT 1
  266. #define M_POST 2
  267.  
  268. /* Object types */
  269. #define REDIRECT_URL -1
  270. #define STD_DOCUMENT 0
  271. #define SCRIPT_NCSA 1
  272. #define SCRIPT_CGI 2
  273.  
  274. #define OPT_NONE 0
  275. #define OPT_INDEXES 1
  276. #define OPT_INCLUDES 2
  277. #define OPT_SYM_LINKS 4
  278. #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS)
  279.  
  280. #define OR_NONE 0
  281. #define OR_LIMIT 1
  282. #define OR_OPTIONS 2
  283. #define OR_FILEINFO 4
  284. #define OR_AUTHCFG 16
  285. #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG)
  286.  
  287.  
  288. #include <stdio.h>
  289. #include <stdlib.h>
  290. #include <string.h>
  291. #include <sys/types.h>
  292. #include <sys/stat.h>
  293. #ifndef AMIGA
  294. #include <sys/file.h>
  295. #endif
  296. #include <sys/socket.h>
  297. #include <ctype.h>
  298. #include <netinet/in.h>
  299. #include <netdb.h>
  300. #include <sys/ioctl.h>
  301. #include <arpa/inet.h>  /* for inet_ntoa */
  302. #include <time.h>  /* for ctime */
  303. #include <signal.h>
  304. #include <errno.h>
  305. #ifndef AMIGA
  306. #include <sys/wait.h>
  307. #endif
  308. #include <pwd.h>
  309. #include <grp.h>
  310.  
  311. #ifndef AMIGA
  312. #ifndef NEXT
  313. #include <unistd.h>
  314. #endif
  315. #endif
  316.  
  317. #ifdef ultrix
  318. #define ULTRIX_BRAIN_DEATH
  319. #endif
  320.  
  321. #ifdef AMIGA
  322. #ifdef AMITCP
  323. #include <inetdlib.h>
  324. #endif
  325. #endif
  326.  
  327. /* Just in case your linefeed isn't the one the other end is expecting. */
  328. #define LF 10
  329. #define CR 13
  330.  
  331. /* For access control */
  332. #define DENY_THEN_ALLOW 0
  333. #define ALLOW_THEN_DENY 1
  334.  
  335. /* Struct shared by access and auth */
  336. typedef struct {
  337.     char *d;
  338.     char opts;
  339.     char override;
  340.  
  341.     int order[METHODS];
  342.  
  343.     int num_allow[METHODS];
  344.     char *allow[METHODS][MAX_SECURITY];
  345.     int num_auth[METHODS];
  346.     char *auth[METHODS][MAX_SECURITY];
  347.  
  348.     char *auth_type;
  349.     char *auth_name;
  350.     char *auth_pwfile;
  351.     char *auth_grpfile;
  352.  
  353.     int num_deny[METHODS];
  354.     char *deny[METHODS][MAX_SECURITY];
  355. } security_data;
  356.  
  357. /* Globals */
  358.  
  359. /* Server config */
  360. extern int standalone;
  361. extern int port;
  362. extern uid_t user_id;
  363. extern gid_t group_id;
  364. extern char server_root[MAX_STRING_LEN];
  365. extern char error_fname[MAX_STRING_LEN];
  366. extern char xfer_fname[MAX_STRING_LEN];
  367. extern char pid_fname[MAX_STRING_LEN];
  368. extern char server_admin[MAX_STRING_LEN];
  369. extern char *server_hostname;
  370. extern char server_confname[MAX_STRING_LEN];
  371. extern char srm_confname[MAX_STRING_LEN];
  372. extern char access_confname[MAX_STRING_LEN];
  373. extern char types_confname[MAX_STRING_LEN];
  374. extern int timeout;
  375.  
  376. /* Document config */
  377. extern char user_dir[MAX_STRING_LEN];
  378. extern char index_name[MAX_STRING_LEN];
  379. extern char access_name[MAX_STRING_LEN];
  380. extern char document_root[MAX_STRING_LEN];
  381. extern char default_type[MAX_STRING_LEN];
  382.  
  383. /* Security config */
  384. extern int num_sec;
  385. #ifndef AMIGA
  386. extern security_data sec[MAX_SECURITY];
  387. #else
  388. extern security_data __far sec[MAX_SECURITY];
  389. #endif
  390.  
  391. /* Auth config */
  392. extern char *auth_type;
  393. extern char *auth_name;
  394. extern char *auth_pwfile;
  395. extern char *auth_grpfile;
  396. extern char user[MAX_STRING_LEN];
  397.  
  398. /* Request information */
  399. extern char *remote_name;
  400. extern int assbackwards;
  401. extern int header_only;
  402. extern char *remote_host;
  403. extern char *remote_ip;
  404. extern char *remote_name;
  405. extern int allow;
  406. extern char allow_options;
  407. extern int num_includes;
  408.  
  409. /* MIME */
  410. extern char auth_line[MAX_STRING_LEN];
  411. extern int content_length;
  412. extern char content_type[MAX_STRING_LEN];
  413. extern char location[MAX_STRING_LEN];
  414. extern char http_accept[HUGE_STRING_LEN];
  415. /* Function prototypes. */
  416.  
  417. /* http_config */
  418. void read_config(VOID_PARMS);
  419. void parse_htaccess(char *dir, char override);
  420. int get_pw(char *user, char *pw);
  421. int in_group(char *user, char *group);
  422. int init_group(char *grpfile);
  423. void kill_group(VOID_PARMS);
  424.  
  425. /* http_alias */
  426. void reset_aliases(VOID_PARMS);
  427. void dump_aliases(VOID_PARMS);
  428. void add_alias(char *f, char *r, int is_script);
  429. void add_redirect(char *f, char *url);
  430. int translate_name(char *name,FILE *fd);
  431. void unmunge_name(char *name);
  432.  
  433. /* http_request */
  434. void process_request(int in, FILE *out);
  435. void send_fd(FILE *f, FILE *fd, char *args);
  436. void send_fd_timed_out(VOID_PARMS);
  437.  
  438. /* http_get */
  439. void send_file(char *file,FILE *fd, char *args);
  440. void process_include(FILE *f, FILE *fd, char *incstring, char *args);
  441. void send_node(char *name, char *args, FILE *fd);
  442. void process_get(int in, FILE *out, char *m, char *url, char *args);
  443.  
  444. /* http_put */
  445. void get_node(char *name, char *args, int in, FILE *out);
  446.  
  447. /* http_script */
  448. void exec_cgi_script(char *method, char *path, char *args, int in, FILE *out);
  449. void exec_get_NCSA(char *path, char *args, FILE *fd);
  450. void exec_post_NCSA(char *path, char *args, int in, FILE *out);
  451.  
  452. /* http_dir */
  453. extern void index_directory(char *name, FILE *fd);
  454.  
  455. /* http_log */
  456. void log_transaction(char *cmd_line);
  457. void log_error(char *err);
  458. void log_reason(char *reason, char *file);
  459. void die(int type, char *err_string, FILE *fd);
  460. void open_logs(VOID_PARMS);
  461. void close_logs(VOID_PARMS);
  462.  
  463. /* http_mime */
  464. void get_mime_headers(int fd);
  465. void send_mime_headers(FILE *fd);
  466. void set_content_type(char *fn);
  467. int scan_script_header(FILE *f, FILE *fd);
  468. void add_type(char *fn, char *t);
  469. void add_encoding(char *fn, char *t);
  470. void set_content_length(int l);
  471. void dump_types(VOID_PARMS);
  472. void init_mime(VOID_PARMS);
  473. void kill_mime(VOID_PARMS);
  474. int is_content_type(char *type);
  475. void dump_default_header(FILE *fd);
  476.  
  477. /* http_access */
  478. void evaluate_access(char *path, struct stat *finfo,int m, int *allow, 
  479.                             char *op);
  480. void kill_security(VOID_PARMS);
  481.  
  482. /* http_auth */
  483. void check_auth(security_data *s, int m);
  484.  
  485. /* util */
  486. void strsubfirst(int start,char *dest, char *src);
  487. void make_full_path(char *src1,char *src2,char *dst);
  488. int is_directory(char *name);
  489. void getparents(char *name);
  490. uid_t uname2id(char *name);
  491. gid_t gname2id(char *name);
  492. int getline(char *s, int n, int f, unsigned int timeout);
  493. int cfg_getline(char *s, int n, FILE *f);
  494. void getword(char *word, char *line, char stop);
  495. void cfg_getword(char *word, char *line);
  496. void get_remote_host(int fd);
  497. char *get_time(VOID_PARMS);
  498. char *gm_timestr_822(time_t t);
  499. void make_dirstr(char *s, int n, char *d);
  500. int count_dirs(char *path);
  501. void strcpy_dir(char *d, char *s);
  502. void unescape_url(char *url);
  503. void escape_url(char *url);
  504. void escape_shell_cmd(char *cmd);
  505. void plustospace(char *str);
  506. void spacetoplus(char *str);
  507. void str_tolower(char *str);
  508. void uudecode(char *s,unsigned char *d,int dl);
  509. #ifdef NEED_STRDUP
  510. char *strdup (char *str);
  511. #endif
  512. #ifdef NEED_PUTENV
  513. void putenv(char *s);
  514. #endif
  515. void ht_putenv(char *n, char *v);
  516. int ind(char *s, char c);
  517. int rind(char *s, char c);
  518. void construct_url(char *d, char *s);
  519. void get_local_host(VOID_PARMS);
  520. int get_portnum(int sd,FILE *out);
  521. int can_exec(struct stat *finfo);
  522. #ifdef NEED_INITGROUPS
  523. int initgroups(const char *name, gid_t basegid);
  524. #endif
  525. #ifdef NEED_ALARM
  526. void alarm(int timeout);
  527. #endif
  528.